package com.bookstore.bean;

/**
 * 封装了购物车中的商品, 包含对商品的引用以及购物车中该商品的数量
 */
public class ShoppingCartItem {

    private Book book;
    private int quantity=1;
    public ShoppingCartItem(Book book, int quantity) {
        this.book = book;
        this.quantity = quantity;
    }

    public void setBook(Book book) {
        this.book = book;
    }

    public ShoppingCartItem(Book book) {
        this.book = book;
        //this.quantity=1;
    }

    public ShoppingCartItem() {
    }

    public Book getBook(){
        return book;
    }

    public int getQuantity(){
        return quantity;
    }

    public void setQuantity(int quantity){
        this.quantity=quantity;
    }

    /**
     * 返回该商品在购物车中的总金额
     * @return
     */
    public double getItemMoney(){
        return book.getPrice()*quantity;
    }

    /**
     * 是商品数量加一
     */
    public void increment(){
        quantity++;
    }

}
